package business {

    import com.adobe.cairngorm.business.ServiceLocator;
    
    import mx.collections.*;
    import mx.rpc.*;
    import mx.rpc.remoting.*;
	
    public class AvatarDelegate
    {
		private var responder:Object;
        private var service:RemoteObject;

        public function AvatarDelegate(re:Object)
        {
	        this.service = ServiceLocator.getInstance().getRemoteObject("avatarService");
            this.responder = re;
        }
        
        public function getConfigs():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getConfigs();
            itemResponder = new ItemResponder(responder["getConfigsResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function getAvatars(page:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getAvatars(page);
            itemResponder = new ItemResponder(responder["getAvatarsResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function getAvatarsBySearch(pattern:String, type:String, page:int=0):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getAvatarsBySearch(pattern,type,page);
            itemResponder = new ItemResponder(responder["getAvatarsBySearchResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }        
        
        public function clearPic(id:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.clearPic(id);
            itemResponder = new ItemResponder(responder["clearPicAvatarResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }        
    }
}

